package com.example.statemachine.demo;

import java.util.ArrayList;
import java.util.List;


public class LibrarySystem {

  static List<Record> recordList = new ArrayList<>();

  // 借书
  public void borrowBook(Book book, Member member) {
    System.out.println("------- 借阅一本书： bookId: "+book.getBookId()+" memberId: "+member.getMemberId());
    recordList.add(new Record(book, member));
  }

  // 还书
  public void returnBook(Book book, Member member) {
    List<Record> recordTmpList=new ArrayList<>();
    recordTmpList.addAll(recordList);
    for (Record record : recordTmpList) {
      if (record.getBook().getBookId() == book.getBookId()
          && record.getMember().getMemberId() == member.getMemberId()) {
        System.out.println("======= 归还一本书： bookId: "+book.getBookId()+" memberId: "+member.getMemberId());
        recordList.remove(record);
      }
    }
  }

  // 显示借书记录
  public void showRecordList() {
    System.out.println("\n******显示借书记录*********");
    for (Record record : recordList) {
      record.show();
    }
    System.out.println();

  }

}
